package com.qf.hospital.service.impl;

import com.qf.hospital.entity.Doctor;
import com.qf.hospital.entity.DoctorExample;
import com.qf.hospital.mapper.DoctorMapper;
import com.qf.hospital.service.DoctorService;
import com.qf.hospital.vo.DoctorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zjw
 * @description 。。。。。
 * @date 2021/10/19 16:03
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public List<Map<String, Object>> findSchedulerByWeek(String week) {
        //1. 调用dockerMapper查询排班信息
        List<String> doctorNameList = doctorMapper.selectDoctorNameBySchedulerAndWeek(week);

        //2. 封装数据
        List<Map<String, Object>> result = new ArrayList<>();
        for (String doctorName : doctorNameList) {
            Map<String,Object> map = new HashMap<>();
            map.put("doctorName",doctorName);
            result.add(map);
        }

        //3. 返回数据
        return result;
    }

    @Override
    public List<DoctorVO> findDoctorByRegisteredIdAndDepartmentId(Integer registeredId, Integer departmentId) {
        //1. 封装查询条件
        DoctorExample example = new DoctorExample();
        DoctorExample.Criteria criteria = example.createCriteria();
        criteria.andRegisteredIdEqualTo(registeredId);
        criteria.andDepartmentIdEqualTo(departmentId);

        //2. 查询
        List<Doctor> doctorList = doctorMapper.selectByExample(example);

        //3. 封装
        List<DoctorVO> result = new ArrayList<>();
        for (Doctor doctor : doctorList) {
            result.add(new DoctorVO(doctor.getDoctorName(),doctor.getDoctorId()));
        }

        //4. 返回
        return result;
    }
}
